<?php 
class ControllerPageIndex extends FrontController {
	public function index($page_id = 0) {  
		
		if (!$page_id) $page_id = G('page_id', 0);
		
		M('catalog/page');
		$page_info = $this->model_catalog_page->getPage($page_id);
   		
		if (!$page_info) {
			return $this->forward('error/not_found');
		}
		
		$this->data['breadcrumbs'][] = array(
			'text'      => $page_info['title'],
			'href'      => U('page/index', 'page_id=' . $page_info['page_id'] . '&seo_url=' . $page_info['seo_url']),
			'separator' => $this->_['text_separator']
		);
		
		$this->document->setTitle($page_info['title']); 
		$this->data['title'] = $page_info['title'];
		$this->data['content'] = v5_html_entity_decode($page_info['content']);
		
		$template = empty($page_info['template']) ? 'index.tpl' : $page_info['template'];		
		$this->display("page/$template");
  	}
	
	public function info($page_id = 0) {
		M('catalog/page');
		
		if (!$page_id) $page_id = G('page_id', 0);
		$page_id = (int) $page_id;    
		
		$page_info = $this->model_catalog_page->getPage($page_id);

		if ($page_info) {
			$output  = '<html dir="ltr" lang="en">' . "\n";
			$output .= '<head>' . "\n";
			$output .= '  <title>' . $page_info['title'] . '</title>' . "\n";
			$output .= '  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">' . "\n";
			$output .= '  <meta name="robots" content="noindex">' . "\n";
			$output .= '</head>' . "\n";
			$output .= '<body>' . "\n";
			$output .= '  <h1>' . $page_info['title'] . '</h1>' . "\n";
			$output .= v5_html_entity_decode($page_info['content']) . "\n";
			$output .= '  </body>' . "\n";
			$output .= '</html>' . "\n";			

			$this->response->setOutput($output);
		}
	}
}
?>